// 按需引入懒加载
import { lazy } from "react";

import LayoutCom from "@/layout/LayoutCom";
import Login from "@/views/Login";

// 重定向
import type { RouteObject } from "react-router-dom";
import { Navigate, Outlet, useRoutes } from "react-router-dom";

// 公共
import lazyLoad from "./lazyLoad";

declare module "react-router" {
  interface IndexRouteObject {
    meta?: any;
  }
  interface NonIndexRouteObject {
    meta?: any;
  }
}

// 添加一个固定的延迟时间，以便你可以看到加载状态
function Time(promise: Promise<any>) {
  return new Promise((resolve) => {
    setTimeout(resolve, 1000);
  }).then(() => promise);
}

export const routes: RouteObject[] = [
  {
    path: "/",
    element: <Navigate to="/home" />,
  },
  // 登录
  {
    path: "/login",
    element: <Login />,
    meta: {
      auth: true, //不需要校验
    },
  },
  {
    path: "/",
    element: <LayoutCom />,
    meta: {
      title: "医疗系统",
      path: "/",
    },
    children: [
      // 首页
      {
        path: "/home",
        element: lazyLoad(lazy(() => Time(import("../views/Home/Home")))),
        meta: {
          title: "",
          path: "/home",
        },
      },

      //预约管理
      {
        path: "/Bookingmsg",
        element: <Outlet />,
        meta: {
          title: "预约管理",
          path: "/Bookingmsg",
        },
        children: [
          {
            index: true,
            element: <Navigate to="/Bookingmsg/BookRegister" />,
          },
          {
            path: "BookRegister", //预约挂号
            element: lazyLoad(
              lazy(() => Time(import("../views/Bookingmsg/BookRegister")))
            ),
            meta: {
              title: "预约挂号",
              path: "BookRegister",
            },
            children: [
              // 详情页
              {
                path: "reservation-detail",
                element: lazyLoad(
                  lazy(() => Time(import("@/components/booking/BookingDetail")))
                ),
              },
            ],
          },
          {
            path: "BookTest", //预约核酸检测
            element: lazyLoad(
              lazy(() => Time(import("../views/Bookingmsg/BookTest")))
            ),
            meta: {
              title: "预约核酸检测",
              path: "BookTest",
            },
          },
          {
            path: "BookMedical", //预约体检
            element: lazyLoad(
              lazy(() => Time(import("../views/Bookingmsg/BookMedical")))
            ),
            meta: {
              title: "预约体检",
              path: "BookMedical",
            },
          },
          {
            path: "BookScheduling", //医生排班
            element: lazyLoad(
              lazy(() => Time(import("../views/Bookingmsg/BookScheduling")))
            ),
            meta: {
              title: "医生排班",
              path: "BookScheduling",
            },
          },
        ],
      },

      // 费用管理
      {
        path: "/Costmsg",
        element: <Outlet />,
        meta: {
          title: "费用管理",
          path: "/Costmsg",
        },
        children: [
          {
            index: true,
            element: <Navigate to="/Costmsg/CostOutConsume" />,
          },
          {
            path: "CostOutConsume", //门诊消费记录
            element: lazyLoad(
              lazy(() => Time(import("../views/Costmsg/CostOutConsume")))
            ),
            meta: {
              title: "门诊消费记录",
              path: "CostOutConsume",
            },
            children: [
              // 消费记录详情页
              {
                path: "CostOutConsume-detail/:id",
                element: lazyLoad(
                  lazy(() =>
                    Time(import("../components/CostOutConsume/COCdetails"))
                  )
                ),
                meta: {
                  title: "消费记录详情",
                  path: "CostOutConsume-detail",
                },
              },
              // 修改详情页
              {
                path: "CostOutConsume-change/:id",
                element: lazyLoad(
                  lazy(() =>
                    Time(import("../components/CostOutConsume/COCchange"))
                  )
                ),
                meta: {
                  title: "消费记录修改",
                  path: "CostOutConsume-change",
                },
              },
              // 新增数据
              {
                path: "CostOutConsume-add",
                element: lazyLoad(
                  lazy(() =>
                    Time(import("../components/CostOutConsume/COCadd"))
                  )
                ),
                meta: {
                  title: "消费记录添加",
                  path: "CostOutConsume-add",
                },
              },
            ],
          },
          {
            path: "CostOutRecharge", //门诊充值记录
            element: lazyLoad(
              lazy(() => Time(import("../views/Costmsg/CostOutRecharge")))
            ),
            meta: {
              title: "门诊充值记录",
              path: "CostOutRecharge",
            },
          },
          {
            path: "CostHospConsume", //住院消费记录
            element: lazyLoad(
              lazy(() => Time(import("../views/Costmsg/CostHospConsume")))
            ),
            meta: {
              title: "住院消费记录",
              path: "CostHospConsume",
            },
          },
          {
            path: "CostHospRecharge", //住院充值记录
            element: lazyLoad(
              lazy(() => Time(import("../views/Costmsg/CostHospRecharge")))
            ),
            meta: {
              title: "住院充值记录",
              path: "CostHospRecharge",
            },
          },
          {
            path: "CostDelivery", //病案配送记录
            element: lazyLoad(
              lazy(() => Time(import("../views/Costmsg/CostDelivery")))
            ),
            meta: {
              title: "病案配送记录",
              path: "CostDelivery",
            },
          },
          {
            path: "CostRefund", //退款记录
            element: lazyLoad(
              lazy(() => Time(import("../views/Costmsg/CostRefund")))
            ),
            meta: {
              title: "退款记录",
              path: "CostRefund",
            },
          },
        ],
      },

      //医院信息
      {
        path: "/Hospitalmsg",
        element: <Outlet />,
        meta: {
          title: "医院信息",
          path: "/Hospitalmsg",
        },
        children: [
          {
            index: true,
            element: <Navigate to="/Hospitalmsg/Doctor" />,
          },
          {
            path: "Doctor", //医生管理
            element: lazyLoad(
              lazy(() => Time(import("../views/Hospitalmsg/Doctor")))
            ),
            meta: {
              title: "医生管理",
              path: "Doctor",
            },
            children: [
              {
                path: "DoctorAdd", //新增医生信息
                element: lazyLoad(
                  lazy(() => Time(import("../views/Hospitalmsg/DoctorAdd/Add")))
                ),
                meta: {
                  title: "新增医生信息",
                  path: "DoctorAdd",
                },
              },
              {
                // 编辑医生信息
                path:'DoctorEdit',
                element:lazyLoad(
                  lazy(() => Time(import("../views/Hospitalmsg/DoctorEdit/Edit")))
                ),
                meta:{
                  title:'编辑医生信息',
                  path:'DoctorEdit'
                }
              }
            ],
          },
          {
            path: "Department", //科室管理
            element: lazyLoad(
              lazy(() => Time(import("../views/Hospitalmsg/Department")))
            ),
            meta: {
              title: "科室管理",
              path: "Department",
            },
          },
          {
            path: "Test", //体检套餐
            element: lazyLoad(
              lazy(() => Time(import("../views/Hospitalmsg/Test")))
            ),
            meta: {
              title: "体检套餐",
              path: "Test",
            },
          },
          {
            path: "Health", //健康百科
            element: lazyLoad(
              lazy(() => Time(import("../views/Hospitalmsg/Health")))
            ),
            meta: {
              title: "健康百科",
              path: "Health",
            },
          },
          {
            path: "Navigation", //医院导航
            element: lazyLoad(
              lazy(() => Time(import("../views/Hospitalmsg/Navigation")))
            ),
            meta: {
              title: "医院导航",
              path: "Navigation",
            },
          },
          {
            path: "Introduction", //医院简介
            element: lazyLoad(
              lazy(() => Time(import("../views/Hospitalmsg/Introduction")))
            ),
            meta: {
              title: "医院简介",
              path: "Introduction",
            },
          },
          {
            path: "Notice", //预约须知
            element: lazyLoad(
              lazy(() => Time(import("../views/Hospitalmsg/Notice")))
            ),
            meta: {
              title: "预约须知",
              path: "Notice",
            },
          },
          {
            path: "DeliveryNotice", //病案配送须知
            element: lazyLoad(
              lazy(() => Time(import("../views/Hospitalmsg/DeliveryNotice")))
            ),
            meta: {
              title: "病案配送须知",
              path: "DeliveryNotice",
            },
          },
          {
            path: "Feedback", //用户反馈管理
            element: lazyLoad(
              lazy(() => Time(import("../views/Hospitalmsg/Feedback")))
            ),
            meta: {
              title: "用户反馈管理",
              path: "Feedback",
            },
          },
        ],
      },

      //系统设置
      {
        path: "/Config",
        element: <Outlet />,
        meta: {
          title: "系统设置",
          path: "/Config",
        },
        children: [
          {
            index: true,
            element: <Navigate to={"/Config/Administrators"} />,
          },
          {
            path: "Administrators", //管理员设置
            element: lazyLoad(
              lazy(() => Time(import("../views/Config/Administrators")))
            ),
            meta: {
              title: "管理员设置",
              path: "Administrators",
            },
          },
          {
            path: "Role", //角色管理
            element: lazyLoad(lazy(() => Time(import("../views/Config/Role")))),
            meta: {
              title: "角色管理",
              path: "Role",
            },
          },
          {
            path: "Title", //职称管理
            element: lazyLoad(
              lazy(() => Time(import("../views/Config/Title")))
            ),
            meta: {
              title: "职称管理",
              path: "Title",
            },
          },
          {
            path: "Message", //消息公告
            element: lazyLoad(
              lazy(() => Time(import("../views/Config/Message")))
            ),
            meta: {
              title: "消息公告",
              path: "Message",
            },
          },
          {
            path: "Changepassword", //个人中心
            element: lazyLoad(
              lazy(() => Time(import("../views/Config/Changepassword")))
            ),
            meta: {
              title: "个人中心",
              path: "Changepassword",
            },
          },
        ],
      },
    ],
  },
];

function GetRoutes() {
  const outlet = useRoutes(routes);

  return outlet;
}

export default GetRoutes;
